﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Media;
using System.IO;

namespace View
{
    class Model:View
    {
        string cardNumber;
        string pinCode;
        public Model(string cardNumber_, string pinCode_)
        {
            this.cardNumber=cardNumber_ ;
            this.pinCode = pinCode_;
        }
     
        /// <summary>
        /// Balance modification.
        /// </summary>
        double getbalance;
        public Model(double getbalance_)
        {
           this.getbalance=getbalance_;
        }
        /// <summary>
        /// Cash upload.
        /// </summary>
        public void Upload()
        {
            StreamReader sr= new StreamReader("amount.txt");
            double adat = Convert.ToDouble(sr.ReadLine());
            adat = adat + getbalance;
            sr.Close();
            StreamWriter sw = new StreamWriter("amount.txt");
            sw.WriteLine(Convert.ToString(adat));
            sw.Close();
         

        }
        /// <summary>
        /// PIN and Card Number control.
        /// </summary>
        /// <param name="cardNumber"></param>
        /// <param name="pinCode"></param>
        /// <returns></returns>
        public bool login(string cardNumber,string pinCode)
        {
            bool jel = true;
            try
            {
                if (cardNumber.Length == 8)
                {
                    int z = 0;

                    for (int i = 0; i < cardNumber.Length; i++)
                    {
                        if (!((cardNumber[i] >= '0') && (cardNumber[i] <= '9')))
                        {
                            throw new ArgumentException();
                        }
                    }


                    for (int i = 4; (i < cardNumber.Length && jel == true); i++)
                    {
                        if ((pinCode.Length == 4) && (cardNumber[i] == pinCode[z]))
                        {
                            z++;
                        }
                        else
                        {
                            return jel = false;
                        }
                    }
                    return jel = true;

                }
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Ne adj betűt te tetű!");
            }
            catch
            {
                MessageBox.Show("Hiba");
            }
            return jel = false;
           
           
        }

    }
}
